import axios from "axios";
import config from "@/config/config.js";
import menuRequest from "@/api/menu.js";

const typeRequest={
    loadMachineType(parentId=0 , callBack){
        let url = config.typeBaseUrl + "/machine/list?parentId=" + parentId;
        axios.get(url).then(res=>{
            callBack(res.data);
        })
    },

    queryType(type,callBack){
        let url = config.typeBaseUrl + "/machine/queryList?";
        if (type){
            if (type.machineTypeName){
                url += "&machineTypeName=" + type.machineTypeName;
            }
            if (type.machineTypeStatus){
                url += "&machineTypeStatus=" + type.machineTypeStatus;
            }
            axios.get(url).then(res=>{
                callBack(res.data);
            })
        }
    },

    addType(type,callBack){
        let url = config.typeBaseUrl + "/machine/add";
        axios.put(url,type).then(res=>{
            callBack(res.data);
        })
    },

    updateTypeParent(typeId){
        let url = config.typeBaseUrl + "/machine/updateTypeParent?typeId=" + typeId;
        axios.put(url).then(res=>{})
    },

    updateType(type,callBack){
        let url = config.typeBaseUrl + "/machine/updateType";
        axios.put(url,type).then(res=>{
            callBack(res.data);
        })
    },

    selectByTypeId(typeId,callBack){
        let url=config.typeBaseUrl + "/machine/selectById?typeId=" + typeId;
        axios.get(url).then(res=>{
            callBack(res.data);
        })
    },

    deleteMachineType(typeId,callBack){
        let url = config.typeBaseUrl + "/machine/updateTypeStatus?typeId="+typeId;
        axios.put(url,typeId).then(res=>{
            callBack(res.data);
        })
    }
}
export default typeRequest;